package com.xuyuan.spring.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Parameter;

@Component
@Aspect
public class CustomAspect {

    @Pointcut("execution(* com.xuyuan.service..*(..))")
    public void point() {
    }

    @Pointcut("@annotation(com.xuyuan.spring.aop.AfterResponse)")
    public void point1() {
    }


    @Before("point()")
    public void before(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Parameter[] parameters = signature.getMethod().getParameters();
        if (parameters.length < 2) ;
        System.out.println("before");
    }

    @After("point1()")
    public void after(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Parameter[] parameters = signature.getMethod().getParameters();
        if (parameters.length < 2) ;
        System.out.println("after");
    }
}
